/*
 * RelayView.cpp
 *
 *  Created on: Nov 30, 2010
 *      Author: ben
 */

#include "RelayView.h"
#include <WProgram.h>
#include "Metro/Metro.h"
#include "Flash/Flash.h"
#include "Thermostat.h"

RelayView::RelayView(LCD *lcd, Thermostat *therm, Metro *relayEventTimer)  : View(lcd) {
  this->thermostat = therm;
  this->relayEventTimer = relayEventTimer;
}

void RelayView::update(Observable *o) {
  if (this->isActive) {
    int relay = thermostat->getRelay();
    unsigned long time = millis();
    long start = relayEventTimer->getStartMillis();

    int seconds = (time-start)/1000;
    int minutes = seconds/60;
    seconds = seconds%60;

    lcd->setCursorLine1();
    lcd->print(F("Compressor: "));
    if (relay) lcd->print("On");
    else lcd->print("Off");
    lcd->setCursorLine2();
    lcd->print(F("Time: "));
    lcd->print(minutes);
    lcd->print(':');
    if (seconds < 10) lcd->print('0');
    lcd->print(seconds);
  }
}
